 $(document).ready(function() {
	var cookie = $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
	/*	if(null == sessionId || "undefined" == sessionId || "" == sessionId){
			window.location.href="login.html";
		} else{*/
			$.getJSON("json/locat.json", function(data) {

 		var locat = data["url"];
 		$.ajax(locat + '/appClient/to_saleReport', {
 			dataType: 'json',
 			type: 'POST',
 			timeout: 10000,
 			xhrFields: {
 				withCredentials: true,
 				useDefaultXhrHeader: false
 			},
 			crossDomain: true,
 			success: function(data) {
 				var list = "";
 				if(data["list"] == "") {
 					var finallist = "<div class='am-count'><span class='am-margin-left am-fl'>没有待完成的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount"] + "</strong>次提货单|合计<strong>" + data["allweight"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist = finallist+"<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list"][j]["clientId"] && data["list"][j]["driverId"] == "total2") {
 								finallist = finallist + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>待完成</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list"][j]["alldegree"] + "次提货||合计" + data["list"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list"][k]["clientId"] && data["list"][k]["driverId"] == "total") {
 								finallist = finallist + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list"][k]["degree"] + "次提货||合计" + data["list"][k]["weight"] + "吨</span></a>";
 								for(var m = 0; m <= data["list"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list"][m]["clientId"] && data["list"][m]["driverId"] != "total" && data["list"][m]["fac_order_no"] == data["list"][k]["fac_order_no"]) {
 										finallist = finallist + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist = finallist + "</li>";
 							}
 						}
 						finallist = finallist + "</ul></div>";

 					}
 				}
 				if(data["list2"] == "") {
 					var finallist2 = "<div class='am-count'><span class='am-margin-left am-fl'>没有已取消的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist2 = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount2"] + "</strong>次提货单|合计<strong>" + data["allweight2"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist2 = finallist2+"<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list2"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list2"][j]["clientId"] && data["list2"][j]["driverId"] == "total2") {
 								finallist2 = finallist2 + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>已取消</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list2"][j]["alldegree"] + "次提货||合计" + data["list2"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list2"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list2"][k]["clientId"] && data["list2"][k]["driverId"] == "total") {
 								finallist2 = finallist2 + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list2"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list2"][k]["degree"] + "次提货||合计" + data["list2"][k]["weight"]+ "吨</span></a>";
 								for(var m = 0; m <= data["list2"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list2"][m]["clientId"] && data["list2"][m]["driverId"] != "total" && data["list2"][m]["fac_order_no"] == data["list2"][k]["fac_order_no"]) {
 										finallist2 = finallist2 + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list2"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list2"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list2"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist2 = finallist2 + "</li>";
 							}
 						}
 						finallist2 = finallist2 + "</ul></div>";

 					}

 				}
 				if(data["list1"] == "") {
 					var finallist1 = "<div class='am-count'><span class='am-margin-left am-fl'>没有已完成的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist1 = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount1"] + "</strong>次提货单|合计<strong>" + data["allweight1"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist2 = finallist2+"<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list1"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list1"][j]["clientId"] && data["list1"][j]["driverId"] == "total2") {
 								finallist1 = finallist1 + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>已完成</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list1"][j]["alldegree"] + "次提货||合计" + data["list1"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list1"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list1"][k]["clientId"] && data["list1"][k]["driverId"] == "total") {
 								finallist1 = finallist1 + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list1"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list1"][k]["degree"] + "次提货||合计" + data["list1"][k]["weight"] + "吨</span>" + "</a>";
 								for(var m = 0; m <= data["list1"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list1"][m]["clientId"] && data["list1"][m]["driverId"] != "total" && data["list1"][m]["fac_order_no"] == data["list1"][k]["fac_order_no"]) {
 										finallist1 = finallist1 + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list1"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list1"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list1"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist1 = finallist1 + "</li>";
 							}
 						}
 						finallist1 = finallist1 + "</ul></div>";

 					}
 				}
 				
 				$("#list").append(finallist);
 				$("#wcl").append(finallist1);
 				$("#qxl").append(finallist2);

 			},
 			error: function() {
 				swal("服务或网络异常，稍后再试！", "", "error");
 			}

 		})

 	})
			//}
 	

 })

 function begintime() {

 	var start = document.getElementById("am-start").value;
 	if(start == "") {
 		swal("开始时间不能为空", " ", "error");
 		document.getElementById("start-time").value = "error";

 	} else {
 		document.getElementById("start-time").value = "success";
 	}

 }

 function endtime() {
 	var start = document.getElementById("am-start").value;
 	var end = document.getElementById("am-end").value;

 	if(end == "") {
 		swal("结束时间不能为空", " ", "error");
 		document.getElementById("end-time").value = "error";
 	}
 	if(start > end) {
 		swal("开始时间不能大于结束时间", " ", "error");
 		document.getElementById("end-time").value = "error"
 	} else {
 		document.getElementById("end-time").value = "success"
 	}
 }

 function bbcx() {
 	var start = document.getElementById("am-start").value;
 	var end = document.getElementById("am-end").value;
 	var result1 = document.getElementById("start-time").value;
 	var result2 = document.getElementById("end-time").value;
 	var cookie = $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
		/*if(null == sessionId || "undefined" == sessionId || "" == sessionId){
			window.location.href="login.html";
		} else{*/
 		if(result1 == "success" && result2 == "success") {
 			$.getJSON("json/locat.json", function(data) {

 		var locat = data["url"];
 		$.ajax(locat + '/appClient/to_saleReport', {
 			dataType: 'json',
 			type: 'POST',
 			timeout: 10000,
 			data :{'begintime':start,'endtime':end},
 			xhrFields: {
 				withCredentials: true,
 				useDefaultXhrHeader: false
 			},
 			crossDomain: true,
 			success: function(data) {
 				$("#doc-modal-1").modal('close');
 				$("#list").empty();
 				$("#wcl").empty();
 				$("#qxl").empty();
 				if(data["list"] == "") {
 					var finallist = "<div class='am-count'><span class='am-margin-left am-fl'>没有待完成的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount"] + "</strong>次提货单|合计<strong>" + data["allweight"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist = finallist+"<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list"][j]["clientId"] && data["list"][j]["driverId"] == "total2") {
 								finallist = finallist + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>待完成</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list"][j]["alldegree"] + "次提货||合计" + data["list"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list"][k]["clientId"] && data["list"][k]["driverId"] == "total") {
 								finallist = finallist + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list"][k]["degree"] + "次提货||合计" + data["list"][k]["weight"] + "吨</span></a>";
 								for(var m = 0; m <= data["list"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list"][m]["clientId"] && data["list"][m]["driverId"] != "total" && data["list"][m]["fac_order_no"] == data["list"][k]["fac_order_no"]) {
 										finallist = finallist + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist = finallist + "</li>";
 							}
 						}
 						finallist = finallist + "</ul></div>";

 					}
 				}
 				if(data["list2"] == "") {
 					var finallist2 = "<div class='am-count'><span class='am-margin-left am-fl'>没有已取消的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist2 = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount2"] + "</strong>次提货单|合计<strong>" + data["allweight2"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist2 = finallist2 + "<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list2"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list2"][j]["clientId"] && data["list2"][j]["driverId"] == "total2") {
 								finallist2 = finallist2 + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>已取消</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list2"][j]["alldegree"] + "次提货||合计" + data["list2"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list2"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list2"][k]["clientId"] && data["list2"][k]["driverId"] == "total") {
 								finallist2 = finallist2 + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list2"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list2"][k]["degree"] + "次提货||合计" + data["list2"][k]["weight"]+ "吨</span></a>";
 								for(var m = 0; m <= data["list2"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list2"][m]["clientId"] && data["list2"][m]["driverId"] != "total" && data["list2"][m]["fac_order_no"] == data["list2"][k]["fac_order_no"]) {
 										finallist2 = finallist2 + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list2"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list2"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list2"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist2 = finallist2 + "</li>";
 							}
 						}
 						finallist2 = finallist2 + "</ul></div>";

 					}

 				}
 				if(data["list1"] == "") {
 					var finallist1 = "<div class='am-count'><span class='am-margin-left am-fl'>没有已完成的订单</span><span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div>";
 				} else {
 					var finallist1 = "<div class='am-count'><span class='am-margin-left am-fl'>共<strong>" + data["allcount1"] + "</strong>次提货单|合计<strong>" + data["allweight1"] + "</strong>吨" +
 						"</span> <span class='am-cxbb am-fr' data-am-modal=\"{target:' #doc-modal-1'}\">" +
 						"选择时间查询>></span></div><div class='am-panel am-panel-default totial'><div class='am-block' >";

 					for(var i = 0; i <= data["list_shopclient"].length - 1; i++) {
 						finallist1 = finallist1+"<ul class='am-list admin-sidebar-list'>";
 						for(var j = 0; j <= data["list1"].length - 1; j++) {
 							if(data["list_shopclient"][i]["c_id"] == data["list1"][j]["clientId"] && data["list1"][j]["driverId"] == "total2") {
 								finallist1 = finallist1 + "<li class='am-panel'><a > <span class='am-margin-left'>" +
 									"<strong>" + data["list_shopclient"][i]["clientname"] + "(" + data["list_shopclient"][i]["clientnumber"] + ")</strong></span> " +
 									"<span class='am-margin-left'>已完成</span><br><span style='text-align:center; display:block;'>" +
 									"&nbsp;&nbsp;共" + data["list1"][j]["alldegree"] + "次提货||合计" + data["list1"][j]["clientweight"] + "</span>" + "</a></li>";
 							}
 						}
 						for(var k = 0; k <= data["list1"].length - 1; k++) {

 							if(data["list_shopclient"][i]["c_id"] == data["list1"][k]["clientId"] && data["list1"][k]["driverId"] == "total") {
 								finallist1 = finallist1 + "<li class='am-panel'>"
 								+"<a> <span class='am-margin-left'>大票号:" + data["list1"][k]["fac_order_no"] + "</span><i class='am-icon-angle-right am-fr '></i> <span class='am-fr'>共" + data["list1"][k]["degree"] + "次提货||合计" + data["list1"][k]["weight"] + "吨</span>" + "</a>";
 								for(var m = 0; m <= data["list1"].length - 1; m++) {
 									if(data["list_shopclient"][i]["c_id"] == data["list1"][m]["clientId"] && data["list1"][m]["driverId"] != "total" && data["list1"][m]["fac_order_no"] == data["list1"][k]["fac_order_no"]) {
 										finallist1 = finallist1 + "<ul class='am-list am-collapse admin-sidebar-sub am-in'>" + "<li><a >" + "<section>" +
 											"<span class='am-margin-left'>车牌号：" + data["list1"][m]["trunkNumber"] + "</span> <span" +
 											"class='am-margin-left'>共" + data["list1"][m]["weight"] + "次</span> <span" +
 											"	class='am-margin-left'>吨数：" + data["list1"][m]["degree"] + "吨</span>" + "	</section>" + "</a></li></ul>";
 									}
 								}
 								finallist1 = finallist1 + "</li>";
 							}
 						}
 						finallist1 = finallist1 + "</ul></div>";

 					}
 				}
 				$("#list").append(finallist);
 				$("#wcl").append(finallist1);
 				$("#qxl").append(finallist2);

 			},
 			error: function() {
 				swal("服务或网络异常，稍后再试！", "", "error");
 				window.location.href = "login.html";
 			}

 		})

 	})
 		} else {
 			swal("请检查选择是否有误！");
 		}
 	//}

 }

 function GetQueryString(name) {
 	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
 	var r = window.location.search.substr(1).match(reg);
 	if(r != null)
 		return unescape(r[2]);
 	return null;
 }